package com.znzz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.znzz.domain.User;
import com.znzz.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 表现层
 */
//@RestController//返回ajax
@RequestMapping("/users")
public class UserController2 {
    @Autowired
    private IUserService userService;

    @GetMapping//请求方式get请求
    public List<User> getAll() {
        return userService.list();
    }

    /* @RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)*/
    @PostMapping
    public boolean save(@RequestBody User user) {//请求体参数
        return userService.save(user);
    }

    @PutMapping
    public boolean update(@RequestBody User user) {
        return userService.updateById(user);
    }

    @DeleteMapping("{id}")
    public boolean delete(@PathVariable String id) {
        return userService.removeById(id);
    }

    /*接收请求路径中占位符的值*/
    @GetMapping("{id}")
    public User getById(@PathVariable String id) {
        return userService.getById(id);
    }

    @GetMapping("{currentPage}/{pageSize}")
    public IPage<User> getPage(@PathVariable int currentPage, @PathVariable int pageSize) {
        return userService.getPage(currentPage, pageSize);
    }

}
